import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { parseParameters, isTenantRoleLevel, getCurrentOrganizationId } from 'utils/utils';
var tenantId = getCurrentOrganizationId();

function templateAssignApi() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/template-assigns") : 'template-assigns';
} // 查询分配模板列表


export function fetchTemplateAssign(_x) {
  return _fetchTemplateAssign.apply(this, arguments);
} // 查询可分配模板列表

function _fetchTemplateAssign() {
  _fetchTemplateAssign = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params);
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(templateAssignApi()), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchTemplateAssign.apply(this, arguments);
}

export function fetchPortalAssignAssignable(_x2) {
  return _fetchPortalAssignAssignable.apply(this, arguments);
} // 批量分配模板

function _fetchPortalAssignAssignable() {
  _fetchPortalAssignAssignable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            param = parseParameters(params);
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(templateAssignApi(), "/assignable"), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchPortalAssignAssignable.apply(this, arguments);
}

export function templateAssignCreate(_x3) {
  return _templateAssignCreate.apply(this, arguments);
} // 删除分配模板

function _templateAssignCreate() {
  _templateAssignCreate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(templateAssignApi(), "/batch-create"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _templateAssignCreate.apply(this, arguments);
}

export function templateAssignDelete(_x4) {
  return _templateAssignDelete.apply(this, arguments);
} // 设置默认分配模板

function _templateAssignDelete() {
  _templateAssignDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            param = parseParameters(params);
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(templateAssignApi()), {
              method: 'DELETE',
              body: param
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _templateAssignDelete.apply(this, arguments);
}

export function templateAssignDefault(_x5) {
  return _templateAssignDefault.apply(this, arguments);
}

function _templateAssignDefault() {
  _templateAssignDefault = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            param = parseParameters(params);
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(templateAssignApi(), "/default"), {
              method: 'PUT',
              query: param
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _templateAssignDefault.apply(this, arguments);
}